// ShooterDlg.cpp : implementation file
//

#include "stdafx.h"
#include "ConfigGUI.h"
#include "global.h"
#include "ConfigGUIDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

extern guiimport_t g_gui_imp;
extern pfnSetShooter g_set_shooter;

/////////////////////////////////////////////////////////////////////////////
// CShooterDlg dialog


CShooterDlg::CShooterDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CShooterDlg::IDD, pParent),
	  m_nDay(17), m_nMonth(4), m_nYear(2008),
	  m_pConfig(NULL)
{
	//{{AFX_DATA_INIT(CShooterDlg)
	m_szName = _T("");
	m_iMode = -1;
	//}}AFX_DATA_INIT
}


void CShooterDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CShooterDlg)
	DDX_Text(pDX, IDE_NAME, m_szName);
	DDV_MaxChars(pDX, m_szName, 32);
	DDX_Text(pDX, IDE_DAY, m_nDay);
	DDV_MinMaxUInt(pDX, m_nDay, 1, 31);
	DDX_Text(pDX, IDE_MONTH, m_nMonth);
	DDV_MinMaxUInt(pDX, m_nMonth, 1, 12);
	DDX_Text(pDX, IDE_YEAR, m_nYear);
	DDV_MinMaxUInt(pDX, m_nYear, 1990, 2010);
	DDX_Radio(pDX, IDR_SELF, m_iMode);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CShooterDlg, CDialog)
	//{{AFX_MSG_MAP(CShooterDlg)
	ON_BN_CLICKED(IDB_SURE, OnSure)
	ON_WM_CLOSE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CShooterDlg message handlers

void CShooterDlg::OnSure() 
{
	// TODO: Add your control notification handler code here
	if (0 == UpdateData())
		TRACE0("update data failed.\n");

	ASSERT(NULL != m_pDate);
	m_pDate->day = m_nDay;
	m_pDate->month = m_nMonth;
	m_pDate->year = m_nYear;
	g_set_shooter(m_szName.GetBuffer(m_szName.GetLength()), m_pDate, m_iMode);
	m_szName.ReleaseBuffer();

	DestroyWindow();
	m_pConfig->ResetBtnShooter();
}

BOOL CShooterDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	m_pDate = (date_ptr)Call_(g_gui_imp.zm, sizeof(date_t));
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CShooterDlg::PostNcDestroy() 
{
	// TODO: Add your specialized code here and/or call the base class
	Call_(g_gui_imp.zf, m_pDate);
	CDialog::PostNcDestroy();
}

void CShooterDlg::OnClose() 
{
	// TODO: Add your message handler code here and/or call default
	CDialog::OnClose();
	DestroyWindow();
	m_pConfig->ResetBtnShooter();
}

BOOL CShooterDlg::PreTranslateMessage(MSG* pMsg) 
{
	// TODO: Add your specialized code here and/or call the base class
	switch (pMsg->message)
	{
	case WM_KEYDOWN:
		switch (pMsg->wParam)
		{
		case VK_ESCAPE:
			SendMessage(WM_CLOSE, 0, 0L);
			return TRUE;
		}
		break;
	case WM_CHAR:
		return TRUE;
	}
	
	return CDialog::PreTranslateMessage(pMsg);
}
